package com.qm.console.dao.model;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

public class MarketStatistics implements Serializable {
    private Long id;

    private Date targetDate;

    private Long registerCount;

    private Long activateCount;

    private Long newUserFirstDayPaidCount;

    private BigDecimal newUserFirstDayPaidTotalPrice;

    private Long paidCount;

    private BigDecimal paidTotalPrice;

    private Long activeCount;

    private BigDecimal deliveryCost;

    private BigDecimal adRevenue;

    private static final long serialVersionUID = 1L;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Date getTargetDate() {
        return targetDate;
    }

    public void setTargetDate(Date targetDate) {
        this.targetDate = targetDate;
    }

    public Long getRegisterCount() {
        return registerCount;
    }

    public void setRegisterCount(Long registerCount) {
        this.registerCount = registerCount;
    }

    public Long getActivateCount() {
        return activateCount;
    }

    public void setActivateCount(Long activateCount) {
        this.activateCount = activateCount;
    }

    public Long getNewUserFirstDayPaidCount() {
        return newUserFirstDayPaidCount;
    }

    public void setNewUserFirstDayPaidCount(Long newUserFirstDayPaidCount) {
        this.newUserFirstDayPaidCount = newUserFirstDayPaidCount;
    }

    public BigDecimal getNewUserFirstDayPaidTotalPrice() {
        return newUserFirstDayPaidTotalPrice;
    }

    public void setNewUserFirstDayPaidTotalPrice(BigDecimal newUserFirstDayPaidTotalPrice) {
        this.newUserFirstDayPaidTotalPrice = newUserFirstDayPaidTotalPrice;
    }

    public Long getPaidCount() {
        return paidCount;
    }

    public void setPaidCount(Long paidCount) {
        this.paidCount = paidCount;
    }

    public BigDecimal getPaidTotalPrice() {
        return paidTotalPrice;
    }

    public void setPaidTotalPrice(BigDecimal paidTotalPrice) {
        this.paidTotalPrice = paidTotalPrice;
    }

    public Long getActiveCount() {
        return activeCount;
    }

    public void setActiveCount(Long activeCount) {
        this.activeCount = activeCount;
    }

    public BigDecimal getDeliveryCost() {
        return deliveryCost;
    }

    public void setDeliveryCost(BigDecimal deliveryCost) {
        this.deliveryCost = deliveryCost;
    }

    public BigDecimal getAdRevenue() {
        return adRevenue;
    }

    public void setAdRevenue(BigDecimal adRevenue) {
        this.adRevenue = adRevenue;
    }

    // 单个用户的注册成本
    public BigDecimal getRegisterCost() {
        if(registerCount == 0 || deliveryCost == null || deliveryCost.equals(new BigDecimal(0))) {
            return BigDecimal.ZERO;
        }
        return deliveryCost.divide(new BigDecimal(registerCount), 2, BigDecimal.ROUND_HALF_UP);
    }

    // 单个设备的安装成本
    public BigDecimal getActivateCost() {
        if(activateCount == 0 || deliveryCost == null || deliveryCost.equals(new BigDecimal(0))) {
            return BigDecimal.ZERO;
        }
        return deliveryCost.divide(new BigDecimal(activateCount), 2, BigDecimal.ROUND_HALF_UP);
    }

    // 注册率
    public String getRegisterRate() {
        if(registerCount == 0 || activateCount == 0) {
            return "0";
        }
        return new BigDecimal(registerCount * 100).divide(new BigDecimal(activateCount), 1, BigDecimal.ROUND_HALF_UP) + "%";
    }

    // 首日付费率
    public String getFirstDayPaidRate() {
        if(newUserFirstDayPaidCount == 0 || registerCount == 0) {
            return "0";
        }
        return new BigDecimal(newUserFirstDayPaidCount * 100).divide(new BigDecimal(registerCount), 1, BigDecimal.ROUND_HALF_UP) + "%";
    }

    // 首日ROI
    public String getFirstDayROI() {
        if(deliveryCost == null || deliveryCost.equals(BigDecimal.ZERO) || newUserFirstDayPaidTotalPrice == null || newUserFirstDayPaidTotalPrice.equals(BigDecimal.ZERO)) {
            return "0";
        }
        return newUserFirstDayPaidTotalPrice.multiply(new BigDecimal(100)).divide(deliveryCost, 1, BigDecimal.ROUND_HALF_UP) + "%";
    }

    // 首日ARPU
    public BigDecimal getFirstDayARPU() {
        if(registerCount == 0 || newUserFirstDayPaidTotalPrice == null || newUserFirstDayPaidTotalPrice.equals(BigDecimal.ZERO)) {
            return BigDecimal.ZERO;
        }
        return newUserFirstDayPaidTotalPrice.divide(new BigDecimal(registerCount), 2, BigDecimal.ROUND_HALF_UP);
    }

    // 首日ARPPU
    public BigDecimal getFirstDayARPPU() {
        if(newUserFirstDayPaidCount == 0 || newUserFirstDayPaidTotalPrice == null || newUserFirstDayPaidTotalPrice.equals(BigDecimal.ZERO)) {
            return BigDecimal.ZERO;
        }
        return newUserFirstDayPaidTotalPrice.divide(new BigDecimal(newUserFirstDayPaidCount), 2, BigDecimal.ROUND_HALF_UP);
    }

    // ROAS
    public String getRoas() {
        if(paidTotalPrice == null || paidTotalPrice.equals(BigDecimal.ZERO) || deliveryCost == null || deliveryCost.equals(BigDecimal.ZERO)) {
            return "0";
        }
        return paidTotalPrice.multiply(new BigDecimal(100)).divide(deliveryCost, 1, BigDecimal.ROUND_HALF_UP) + "%";
    }

    // 付费率
    public String getPaidRate() {
        if(paidCount == 0 || activeCount == 0) {
            return "0";
        }
        return new BigDecimal(paidCount * 100).divide(new BigDecimal(activeCount), 1, BigDecimal.ROUND_HALF_UP) + "%";
    }

    // 活跃用户ARPU
    public BigDecimal getARPU() {
        if(activeCount == 0 || paidTotalPrice == null || paidTotalPrice.equals(BigDecimal.ZERO)) {
            return BigDecimal.ZERO;
        }
        return paidTotalPrice.divide(new BigDecimal(activeCount), 2, BigDecimal.ROUND_HALF_UP);
    }

    // 活跃用户ARPPU
    public BigDecimal getARPPU() {
        if(paidCount == 0 || paidTotalPrice == null || paidTotalPrice.equals(BigDecimal.ZERO)) {
            return BigDecimal.ZERO;
        }
        return paidTotalPrice.divide(new BigDecimal(paidCount), 2, BigDecimal.ROUND_HALF_UP);
    }

    // 当日付费用户成本
    public BigDecimal getPayUserCost() {
        if(newUserFirstDayPaidCount == 0 || deliveryCost == null || deliveryCost.equals(BigDecimal.ZERO)) {
            return BigDecimal.ZERO;
        }
        return deliveryCost.divide(new BigDecimal(newUserFirstDayPaidCount), 2, BigDecimal.ROUND_HALF_UP);
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName());
        sb.append(" [");
        sb.append("Hash = ").append(hashCode());
        sb.append(", id=").append(id);
        sb.append(", targetDate=").append(targetDate);
        sb.append(", registerCount=").append(registerCount);
        sb.append(", activateCount=").append(activateCount);
        sb.append(", newUserFirstDayPaidCount=").append(newUserFirstDayPaidCount);
        sb.append(", newUserFirstDayPaidTotalPrice=").append(newUserFirstDayPaidTotalPrice);
        sb.append(", paidCount=").append(paidCount);
        sb.append(", paidTotalPrice=").append(paidTotalPrice);
        sb.append(", activeCount=").append(activeCount);
        sb.append(", deliveryCost=").append(deliveryCost);
        sb.append(", adRevenue=").append(adRevenue);
        sb.append(", serialVersionUID=").append(serialVersionUID);
        sb.append("]");
        return sb.toString();
    }
}